package com.java.manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.common.model.Result;
import com.java.manage.dao.MaintainAccMapper;
import com.java.manage.dao.MaintainMapper;
import com.java.manage.model.Maintain;
import com.java.manage.model.MaintainAcc;
import com.java.manage.service.MaintainAccService;
import com.java.manage.service.MaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MaintainAccServiceImpl implements MaintainAccService {

    @Autowired
    private MaintainAccMapper maintainAccMapper;

    @Override
    public Result save(MaintainAcc maintainAcc) {
        maintainAccMapper.save(maintainAcc);
        return Result.success();
    }

    @Override
    public Result modify(MaintainAcc maintainAcc) {
        maintainAccMapper.modify(maintainAcc);
        return Result.success();
    }

    @Override
    public Result remove(int[] ids) {
        for (int id : ids) {
            maintainAccMapper.remove(id);
        }
        return Result.success();
    }

    @Override
    public Result list(MaintainAcc maintainAcc) {
        PageHelper.startPage(maintainAcc.getPageNum(), maintainAcc.getPageSize());

        List<MaintainAcc> list = maintainAccMapper.list(maintainAcc);
        PageInfo<MaintainAcc> pageInfo = new PageInfo(list);

        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());
        return Result.success(map);
    }

    @Override
    public Result get(int id) {
        MaintainAcc maintainAcc = maintainAccMapper.get(id);
        return Result.success(maintainAcc);
    }

    @Override
    public Result getGenerate(List<MaintainAcc> maintainAcc) {
        Integer id = null;
        for (MaintainAcc mai : maintainAcc) {
            id = mai.getId();
        }
        MaintainAcc maintain1 = maintainAccMapper.get(id);
        return Result.success(maintain1);
    }
}
